//
//  HHBaseNavViewController.m
//  YSJ
//
//  Created by 花花 on 2016/12/15.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHBaseNavViewController.h"

@interface HHBaseNavViewController ()

@end

@implementation HHBaseNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self setupNav];
}


-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
#pragma mark - 可在此方法中拦截所有push 进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    
    if (self.childViewControllers.count>0) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [btn setImage:[UIImage imageNamed:@"nav_return_normal"] forState:UIControlStateNormal];
        
        
        //返回键隔得太远
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
//                [btn sizeToFit]; //等价于下面2行
        btn.size = CGSizeMake(100, 30);
        //让按钮内部的所有的内容左对齐
//        btn.backgroundColor = [UIColor redColor];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        
        btn.contentMode = UIRectCornerTopLeft; //这个一般是针对是 img 的设置,而按钮的设置是通过contentHorizontalAlignment才有效果的
        
        
        [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
    
}


- (void)backClick
{
    [self popViewControllerAnimated:YES];
}

@end
